package com.example.housekeeping.controller;

import com.example.housekeeping.pojo.dto.CommentAddNewDTO;
import com.example.housekeeping.pojo.dto.CommentUpdateDTO;
import com.example.housekeeping.pojo.dto.MessageAddNewDTO;
import com.example.housekeeping.pojo.dto.MessageUpdateDTO;
import com.example.housekeeping.pojo.entity.Message;
import com.example.housekeeping.pojo.vo.CommentListItemVO;
import com.example.housekeeping.pojo.vo.CommentStandardVO;
import com.example.housekeeping.pojo.vo.MessageListItemVO;
import com.example.housekeeping.pojo.vo.MessageStandardVO;
import com.example.housekeeping.service.CommentService;
import com.example.housekeeping.service.MessageService;
import com.example.housekeeping.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 留言表(Message)表控制层
 *
 * @author bob
 * @since 2023-03-30 14:26:07
 */
@Api("04.留言管理")
@Slf4j
@RestController
@RequestMapping("/message")
public class MessageController {
    @Autowired
    private MessageService messageService;

    @ApiOperation("添加留言")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(MessageAddNewDTO messageAddNewDTO) {
        log.debug("开始处理【添加留言】的请求，参数：{}", messageAddNewDTO);
        messageService.addNew(messageAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("根据id删除留言")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "评论id", value = "id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id) {
        log.debug("开始处理【根据id删除留言】的请求，参数：{}", id);
        messageService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改留言详情")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "留言id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> updateInfoById(@PathVariable Long id, MessageUpdateDTO messageUpdateDTO) {
        log.debug("开始处理【修改留言详情】的请求，参数ID：{}, 新数据：{}", id, messageUpdateDTO);
        messageService.updateById(id, messageUpdateDTO);
        return JsonResult.ok();
    }

    @ApiOperation("根据id查询详情")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id", value = "留言id", required = true, dataType = "long")
    @GetMapping("/{id:[0-9]+}")
    public JsonResult<MessageStandardVO> getStandardById(@PathVariable Long id) {
        log.debug("开始处理【根据id查询留言详情】的请求，参数：{}", id);
        MessageStandardVO standardById = messageService.getStandardById(id);
        return JsonResult.ok(standardById);
    }

    @ApiOperation("查询留言列表")
    @ApiOperationSupport(order = 410)
    @GetMapping("")
    public JsonResult<List<MessageListItemVO>> list() {
        log.debug("开始处理【评论列表】的请求，参数：{}");
        List<MessageListItemVO> list = messageService.list();
        return JsonResult.ok(list);
    }



}

